from __future__ import absolute_import
#import os
from forest.tool import Tool
import logging
#import subprocess as sp

from forest.registry import register_tool
from forest.tools.system.execute import run

logger = logging.getLogger('forest.tools.system.format')

@register_tool('system.format')
def format(partition, fs):
    '''
    calls relevant mkfs or mkswap in a subprocess.
    '''
    Tool.SIGNAL_TOOL_START(format, level=logging.DEBUG, message='Format: %s %s' % (partition, fs))
    if fs == 'swap':
        cmd = 'mkswap'
    else:
        cmd = 'mkfs.{0}'.format(fs)

    run([cmd, partition])
